<!DOCTYPE html>
<html lang="en">
<head>
    {include file="common/meta_new" /}
</head>
<body class="F6">

<script src="/static/js/layer/layer.js"></script>
<script>

    function allin() {
        var allMoney = "{$user['h5_money']}";
        $("#withdrawMoney").val(allMoney);
    }

    function switchTab(that, paytype) {
        if (paytype == 2) {
            showCard();
        } else {
            hideCard();
        }
        $("#tab").children('.item').removeClass('active');
        $(that).addClass('active');
        $("#payType").val(paytype)
    }

    function submitPay() {
        var payType = $("#payType").val();
        var payMoney = $("#withdrawMoney").val();
        var bankNum = $("#bankNum").val();
        var bankName = $("#bankName").val();
        var userName = $("#userName").val();
        if (payMoney <= 0) {
            layer.msg('提现金额必须大于 0', {icon: 2});
            return;
        }
        if (payType != 0 && payType != 1 && payType != 2) {
            layer.msg('请选择收款方式', {icon: 2});
            return;
        }

        if (payType == 2) {
            if (userName == '') {
                layer.msg('请输入真实姓名！', {icon: 2});
                return;
            }
            if (bankName == '') {
                layer.msg('请输入银行名称！', {icon: 2});
                return;
            }
            if (bankNum == '') {
                layer.msg('请输入银行卡号！', {icon: 2});
                return;
            }
        }


        $.post("{:url('index/user/withdraw')}", {
            "payType": payType, "payMoney": payMoney, "bankNum": bankNum, "bankName": bankName, "userName": userName
        }, function (res) {
            if (res.code == 0) {
                layer.msg(res.msg, {icon: 2})
            } else {
                layer.msg(res.msg, {icon: 1}, function () {
                    location.reload();
                });
            }
        }, "json");

    }

    function showCard() {
        $(".top-wrap").css('height', "7.1rem");
    }

    function hideCard() {
        $(".top-wrap").css('height', "3.4933rem");
    }


</script>

<div id="app" class="withdrawal-page">
    <!-- header -->
    <div class="header">
        <div class="header-height"></div>
        <div class="header-wrap">
            <div class="header-content">
                <div class="left">
                    <a href="javascript: history.back(-1)">
                        <div class="go-back"><img src="/static/images/go-back.png" alt=""></div>
                    </a>
                    <div class="text">提现</div>
                </div>
                <div class="title"></div>
            </div>
        </div>
    </div>
    <div class="top-wrap" style="height: auto">
        <div class="title">提现金额</div>
        <div class="amount-box">
            <div class="symbol">￥</div>
            <input id="withdrawMoney" type="text" value="" placeholder="请输入提现金额">
            <input id="payType" type="hidden" value="2">

        </div>
        <div class="hr"></div>

        {if $user['bank_name']==''||$user['bank_name']==''||$user['card_num']=='' }
        <div class="bottom-text">
            <div class="text">没有设置收款方式</div>
            <a href="{:url('index/user/payType',['callback'=>'1']);}">
                <div class="btn">立即设置</div>
            </a>
        </div>
        {else /}
        <div class="bottom-text">
            <div class="text">可提现金额：￥{$user["h5_money"]}</div>
            <div class="btn" onclick="allin()">全部提现</div>
        </div>
        <div class="amount-box">
            <div class="symbol">B:</div>
            <input id="bankName" readonly="ture" type="text" value="{$user['bank_name']}" placeholder="请输入银行名称">
        </div>
        <div class="amount-box">
            <div class="symbol">R:</div>
            <input id="userName" readonly="ture" type="text" value="{$user['user_name']}" placeholder="请输入真实姓名">
        </div>
        <div class="amount-box">
            <div class="symbol">No:</div>
            <input id="bankNum" readonly="ture" type="text" value="{$user['card_num']}" placeholder="请输入银行卡号">
        </div>
        {/if}
    </div>
    <div class="payway-wrap">
        <div class="title">到账方式</div>
        <div id="tab" class="list">
            <!--            <div class="item active" onclick="switchTab(this,0)" >
                            <div class="image">
                                <img src="/static/images/WeChat.png" alt="">
                            </div>
                            <div class="text">微信</div>
                            <img class="sel-img" src="/static/images/selected.png" alt="">
                        </div>
                        <div class="item" onclick="switchTab(this,1)" >
                            <div class="image">
                                <img src="/static/images/zfb.png" alt="">
                            </div>
                            <div class="text">支付宝</div>
                            <img class="sel-img" src="/static/images/selected.png" alt="">
                        </div>-->
            <div class="item active">
                <div class="image">
                    <img src="/static/images/UnionPay.png" alt="">
                </div>
                <div class="text">银行卡</div>
                <img class="sel-img" src="/static/images/selected.png" alt="">
            </div>
        </div>
    </div>

    <div class="bottom-btn" onclick="submitPay()">立即提现</div>
</div>
<script src="/static/js/common.js"></script>
</body>
</html>